package test.testThread;

import java.util.Date;

public class TraditionalThreadSynchronized {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Date date1=new Date();
		final Date date2=new Date();
		final Output output=new Output();
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true){
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					output.print("111111",date1);
				}
			}
		}).start();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true){
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					output.print("222222",date2);
				}
			}
		}).start();
	}
}

class Output{
	public void print(String name,Date date){
		synchronized(date){
			for(int i=0;i<name.length();i++){
				System.out.print(name.charAt(i));
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println();
		}
	}
	
	public  void print2(String name,Date date){
		synchronized(date){
			for(int i=0;i<name.length();i++){
				System.out.print(name.charAt(i));
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println();
			}
		}
	
	public synchronized static void print3(String name){
		for(int i=0;i<name.length();i++){
			System.out.print(name.charAt(i));
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println();
	}
}
